//
//  MYMessageTableViewController.swift
//  MYWeibo
//
//  Created by Magic Yu on 16/4/13.
//  Copyright © 2016年 Magic Yu. All rights reserved.
//

import UIKit

class MYMessageTableViewController: MYVisitorTableViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        setupUI()
        
    }

    private func setupUI() {
        //设置访客视图信息
        visitorView?.setVisitorInfo("登录后，别人评论你的微博，发给你的消息，都会在这里收到通知", imageName: "visitordiscover_image_message")
        
        //设置导航条
        //CUICatalog: Invalid asset name supplied:  图片设置空字符串 就会报这个问题
        navigationItem.rightBarButtonItem = UIBarButtonItem(imageName: nil, title: "发现群", target: self, action: "findGroup")
        tabBarItem.badgeValue = "99"
        //setBadgeBackGround()
    }
    
    private func setBadgeBackGround() {
    
        //遍历tabBar的子视图
        for subview in tabBarController!.tabBar.subviews {
            if subview.isKindOfClass(NSClassFromString("UITabBarButton")!) {
                for v in subview.subviews {
                    if v.isKindOfClass(NSClassFromString("_UIBadgeView")!) {
                        for bgView in v.subviews {
                            if bgView.isKindOfClass(NSClassFromString("_UIBadgeBackground")!) {
                                //print("zhongyuzhaodaoni")
                                //print(bgView)
                                //通过KVC 来设置成员变量 打断点 通过调试台查看成员变量
                                bgView.setValue(UIImage(named: "main_badge"), forKey: "_image")
                            }
                        }
                    }
                }
            }
        }
        
      
    }
    

    @objc private func findGroup() {
        print("发现群")
        //修改badgeValue 
        //将badge设置为nil后 再点击发现按钮 badge会恢复系统的样式 所以要将UITabBarItem封装
        tabBarItem.badgeValue = nil
        tabBarItem.badgeValue = "\(random()%50)"
    }

}
